javascript:(function(){
	var currentStamina = 0;
	var currentSprees = 0;
	var currentStaminaReqd = 0;
	var locationPlacement = 0;
	var locations = [7, 8, 9, 10, 11];
	var scout = false;
	var scoutActive = false;
	var arsonist = false;
	var arsonistActive = false;
	var slot = 1;
	var timesBoardRobbed = 0;
	
	function AjxRequest(url, handler, errorhandler){
		var zserver = /\/\/(.*)\.mafiawars/.exec(document.location.href)[1];
		if(url.indexOf('html_server.php') >= 0){
			url = url.substr(url.indexOf('?')+1);
		}
		var preurl = '//'+zserver+'.mafiawars.zynga.com/mwfb/remote/html_server.php?';
		function processRequest() {
			$.ajax({
				type: "POST",
				url: preurl+url,
				data: params,
				cache: false,
				timeout: 30000,
				success: handler,
				error: errorhandler
			});
		}
		processRequest()
	}
	
	function logit(msg){
		setTimeout(function(){
			throw new Error(msg);
		}, 0);
	}
	
	function next_location() {
		if (locationPlacement >= locations.length) {
			alert('DONE!!!!!!!')
			return;
		}else{
			AjxRequest('xw_controller=travel&xw_action=travel&xw_city=7&destination='+locations[locationPlacement]+'&from=robbing&zone=1&nextParams=&menu=travel', function(msg){
				if(/Robbing/.test(msg)){
					logit('we are on robbing page..')
					try{
						currentStamina = parseInt(/user_stamina.*?(\d+)/.exec(msg)[1]);
						currentSprees = $(msg).find('#call_sprees_left').text();
						currentStaminaReqd = parseInt($(msg).find('#oneClickRobAll').text().substring(9));
					}catch(maybeNan){
						alert('something bad happened!')
						return;
					}
					scout = arsonist = false;
					timesBoardRobbed = 0;
					slot = 1;
					checkCrew();
				}else{
					logit('robbing page failed to load, reloading..')
					travelCityRobbing();
				}
			}, function(fail){travelCityRobbing();})
		}
	}
		
	function checkCrew(){
		if(!scout){
			scout = true;
			slot = 1;
			activateCrew()
			return;
		}
		if(!arsonist){
			arsonist = true;
			slot = 2;
			activateCrew()
			return;
		}
		if(scout && arsonist){
			doTheRobs();
		}
	}
	
	function activateCrew(){
		var http;
		if(/https/.test(window.location.href)){ 
			http = 'https' 
		}else{ 
			http = 'http' 
		}
		var params = '';
		var linky = http+'://facebook-ca2.mafiawars.zynga.com/mwfb/remote/html_server.php?xw_controller=CityCrew&xw_action=activate&isajax=1&crew_city='+locations[locationPlacement]+'&crew_type=rob&crew_dsp_type=rob&crew_slot='+slot;
		$.ajax({
			type: "POST",
			url: linky,
			timeout: 30000,
			data: params,
			success: function (msg) {
				var _json = JSON.parse(msg);
				var crewmemberResult;
				if(_json.data.crewstatus == 'ok'){
					if(slot == 1){
						scoutActive = true;
					}else{
						arsonistActive = true;
					}
					logit('activated !');
				}else if(_json.data.crewmsg){
					logit('is on cooldown :/');
					alert('there is a crew on cooldown, bail time as i dont know what to code for here yet..')
					return;
				}
				checkCrew();
			},
			error: function (req, status, err) {
				return;
			}
		});
	}
	
	function doTheRobs(){
		if(currentStamina >= currentStaminaReqd){
			if(currentSprees < 3){
				alert('not enough sprees, stopping')
				return;
			}
			AjxRequest('xw_controller=robbing&xw_action=rob_all&xw_city='+locations[locationPlacement], function(msg){
				if(/You did not have a 1/.test(msg)){
					logit('You did not have a 1-Click Robbery boost to use!')
					return;
				}else if(/You do not have enough stamina to rob/.test(msg)){
					logit('You do not have enough stamina to rob')
					return;
				}
				if(/Get New Targets /.test(msg)){
					AjxRequest('xw_controller=robbing&xw_action=refresh&xw_city='+locations[locationPlacement], function(page){
						timesBoardRobbed++;
						if(timesBoardRobbed > 2){
							locationPlacement++;
							next_location();
							return;
						}
						currentStamina = parseInt(/user_stamina.*?(\d+)/.exec(page)[1]);
						currentSprees = $(page).find('#call_sprees_left').text();
						currentStaminaReqd = parseInt($(page).find('#oneClickRobAll').text().substring(9));
						doTheRobs();
					})
				}
			})
		}else{
			alert('not enough stamina..')
		}
	}
	
	next_location()
	
	/*add analytics*/
	function loadContent(file) {
		var head=document.getElementsByTagName('head').item(0);
		var scriptTag=document.getElementById('loadScript');
		if(scriptTag)head.removeChild(scriptTag);
		script=document.createElement('script');
		script.src=file;
		script.type='text/javascript';
		script.id='loadScript';
		head.appendChild(script);
		setTimeout(load,1000);
	}
	loadContent('https://www.google-analytics.com/ga.js');
	function load() {
		try {
			var pageTracker=_gat._getTracker("UA-35022618-1");
			pageTracker._trackPageview("/rob3x");
		} catch(err){}
	}
	/*end analytics*/
})()